package com.moran.util;

import com.fasterxml.jackson.databind.JsonNode;
import com.github.victools.jsonschema.generator.SchemaGenerator;
import com.moran.domain.WeatherInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

@Component
public class CommonUtil {

    @Autowired
    private SchemaGenerator schemaGenerator;

    /**
     * 将类对象转换成JSON字符串
     *
     * @param classz
     * @return
     */
    public String getJsonSchema(Class<?> classz) {
        // 将实体类转换成json字符串
        JsonNode jsonSchema = schemaGenerator.generateSchema(classz);
        String jsonStr = jsonSchema.toPrettyString();
        return jsonStr;
    }

}
